$(function() {

    $( "#dialog:ui-dialog" ).dialog( "destroy" );

    $( "#dialog-modal" ).dialog({
        
        modal: true
    });

    $( "#dialog:ui-dialog" ).dialog( "destroy" );

    $( ".message" ).dialog({
        modal: true
        
     });
                
    $( "#ProfilDateNaissance" ).datepicker({
                    
        changeMonth: true,
        changeYear: true,
        yearRange: 'c-100:c'
 
    });


    $( "#destinataire" )
    
        // don't navigate away from the field on tab when selecting an item
	.bind( "keydown", function( event ) {
            
            if ( event.keyCode === $.ui.keyCode.TAB &&
		$( this ).data( "autocomplete" ).menu.active ) {
                
			event.preventDefault();
				
                            }
			})
			.autocomplete({
                            
				source: function( request, response ) {
                                    
					$.getJSON( "/javascripts/expediteur", {
						term: extractLast( request.term )
					}, response );
				},
				search: function() {
					// custom minLength
					var term = extractLast( this.value );
					if ( term.length < 2 ) {
						return false;
					}
				},
				focus: function() {
					// prevent value inserted on focus
					return false;
				},
				select: function( event, ui ) {
					var terms = split( this.value );
					// remove the current input
					terms.pop();
					// add the selected item
					terms.push( ui.item.value );
					// add placeholder to get the comma-and-space at the end
					terms.push( "" );
					this.value = terms.join( "," );
					return false;
				}
			});
                        
                        $("#pikame").PikaChoose({
                            showTooltips:true,
                            autoPlay:true,
                            transition:[0]
                        
                         });
                        
    var  test = $( "#ProfilDateNaissance" ).datepicker.regional['fr'];          

});

function split( val ) {
    
    return val.split( /,\s*/ );
        
}

function extractLast( term ) {
    
    return split( term ).pop();
		
}



function online(){
    
    $.ajax({
        url: "/utilisateurs/online",
        cache: false,
        success: function(html){
            
            $("#online").html(html);
            
        }
    })
    
}

function utilisateurOnline(pseudo){
    

    $.ajax({
        
        url: "/utilisateurs/utilisateur_online/" + pseudo,
        cache: false,
        success: function(html){       
        
            $("#online_"+ pseudo).html(html);
            
        }
    })
}

setInterval('online()',1000);
